package vcp.client.GUI.mvc.view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.text.NumberFormat;
import java.util.List;

import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.BevelBorder;
import javax.swing.border.MatteBorder;
import javax.swing.border.SoftBevelBorder;

import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import vcp.client.GUI.events.ComplaintUpdateEvent;
import vcp.client.interfaces.listeners.IComplaintUpdateListener;
import vcp.client.utility.Common;
import vcp.client.utility.Common.UserNotification;
import vcp.client.utility.UtilityHelper;
import vcp.entity.Complaint;
import vcp.enums.ComplaintType.ComplaintResolve;
import vcp.enums.ComplaintType.ComplaintStatus;
import vcp.enums.PopUpMessageType;
/**
 * <p> user interface for handling complaint class </p>
 * @author VCP team
 *
 */
public class UICompHandleView extends UIAbstractView implements ItemListener, KeyListener
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 5280417648856598494L;

	private JComboBox <Integer> cbComplaintID;
	private JTextField tfCustomerName;
	private JTextField tfCustomerSureName;
	private JTextField tfCustomerEmail;
	private JComboBox <ComplaintStatus> cbComplaintStatus;
	private JComboBox <ComplaintResolve> cbComplaintResolve;
	private JFormattedTextField ftfRefundAmount;
	private JTextArea taComplaintResolve;
	private JTextArea taComplaintText;
	private JButton btnSubmit;

	private Integer selectedComplaintID;

	private IComplaintUpdateListener complaintUpdateListener;
	private JTextField tfComplaintType;
	private JTextField tfOpenDate;
	/**
	 * setter
	 * @param complaintUpdateListener
	 */
	public void setComplaintUpdateListener ( IComplaintUpdateListener complaintUpdateListener )
	{
		this.complaintUpdateListener = complaintUpdateListener;
	}
	/**
	 * constructor
	 */
	public UICompHandleView ()
	{
		super();
		this.selectedComplaintID = null;
		this.ftfRefundAmount.setText("0");
	}

	/****************************************************************************************************************************
	 *** Public methods ***
	 ****************************************************************************************************************************/
	/**
	 * getter
	 * @return selected complaint id
	 */
	public Integer getCurrentComplaintID ()
	{
		return this.selectedComplaintID;
	}
	/**
	 * method loads all complaint Id's
	 * @param complaints
	 */
	public void loadAllComplaintIDs ( List <Complaint> complaints )
	{
		this.cbComplaintID.removeAllItems();
		for ( Complaint complaint : complaints )
		{
			this.cbComplaintID.addItem(complaint.getID());
		}

		this.setRelevantComponentsEnabled(true);
	}
	/**
	 * method adds new complaint id
	 * @param complaintID
	 */
	public void addNewComplaintID ( int complaintID )
	{
		if ( ! this.cbComplaintID.isEnabled() )
		{
			this.setRelevantComponentsEnabled(true);
		}

		DefaultComboBoxModel <Integer> model = (DefaultComboBoxModel <Integer>) this.cbComplaintID.getModel();
		if ( model.getIndexOf(complaintID) == - 1 )
		{
			this.cbComplaintID.addItem(complaintID);
		}
	}
	/**
	 * method loads complaint info on screen
	 * @param complaint
	 */
	public void loadComplaintInfo ( Complaint complaint )
	{
		this.selectedComplaintID = complaint.getID();

		this.fillAllTexts(complaint);

		ComplaintStatus status = complaint.getStatus();
		this.cbComplaintStatus.setSelectedItem(status);

		if ( complaint.isHistory() )
		{
			this.cbComplaintStatus.setEnabled(false);
			this.cbComplaintResolve.setEnabled(false);
			this.ftfRefundAmount.setEnabled(false);
			this.taComplaintResolve.setEnabled(false);
			this.btnSubmit.setEnabled(false);
		}
		else
		{
			this.setResolveEnabledAccordingStatus();
		}
	}
	/**
	 * method fdisplays all texts in complaint
	 * @param complaint
	 */
	private void fillAllTexts ( Complaint complaint )
	{
		this.tfCustomerName.setText(complaint.getCustomerOfComplaint().getUserFirstName());
		this.tfCustomerSureName.setText(complaint.getCustomerOfComplaint().getUserLastName());
		if ( ! this.tfCustomerEmail.getText().equalsIgnoreCase(complaint.getCustomerOfComplaint().getUserEmail()) )
		{
			this.tfCustomerEmail.setText(complaint.getCustomerOfComplaint().getUserEmail());
		}

		DateTimeFormatter dtf = DateTimeFormat.forPattern("dd/MM/yyyy HH:mm");
		this.tfOpenDate.setText(dtf.print(complaint.getOpenDate()));

		this.taComplaintText.setText(complaint.getText());
		this.tfComplaintType.setText(complaint.getType().toString());
	}
	/**
	 * method sets resolve to enabled according to complaint status
	 */
	private void setResolveEnabledAccordingStatus ()
	{
		this.cbComplaintStatus.setEnabled(true);

		ComplaintStatus status = (ComplaintStatus) this.cbComplaintStatus.getSelectedItem();
		switch ( status )
		{
			case OPENED:
				this.cbComplaintResolve.setEnabled(false);
				this.ftfRefundAmount.setEnabled(false);
				this.taComplaintResolve.setEnabled(false);
				this.btnSubmit.setEnabled(false);
				break;
			case PENDING:
				this.cbComplaintResolve.setEnabled(false);
				this.ftfRefundAmount.setEnabled(false);
				this.taComplaintResolve.setEnabled(false);
				this.btnSubmit.setEnabled(true);
				break;
			case CLOSED:
				this.cbComplaintResolve.setEnabled(true);
				this.taComplaintResolve.setEnabled(true);

				ComplaintResolve resolve = (ComplaintResolve) this.cbComplaintResolve.getSelectedItem();
				this.ftfRefundAmount.setEnabled(resolve == ComplaintResolve.REFUND);
				this.btnSubmit.setEnabled(resolve != ComplaintResolve.REFUND);
				break;
		}
		if ( status == ComplaintStatus.PENDING )
		{

		}
		else if ( status == ComplaintStatus.CLOSED )
		{

		}
	}
	/**
	 * sets relevant components enabled on screen
	 * @param enable
	 */
	private void setRelevantComponentsEnabled ( boolean enable )
	{
		this.cbComplaintID.setEnabled(enable);
		this.cbComplaintStatus.setEnabled(enable);
	}

	/****************************************************************************************************************************
	 *** UIAbstractView methods ***
	 ****************************************************************************************************************************/
	@Override
	public void clearView ()
	{
		this.resetView();
		this.onScreen = false;
		this.selectedComplaintID = 0;
		this.cbComplaintID.setModel(new DefaultComboBoxModel <Integer>());
		this.cbComplaintResolve.setSelectedIndex(0);
		this.cbComplaintStatus.setSelectedIndex(0);
	}

	@Override
	public void resetView ()
	{
		this.tfCustomerName.setText("");
		this.tfCustomerSureName.setText("");
		this.tfCustomerEmail.setText("");

		this.tfOpenDate.setText("");

		this.tfComplaintType.setText("");

		this.taComplaintText.setText("");
		this.taComplaintResolve.setText("");
	}

	@Override
	protected void setupLayout ()
	{
		this.setPreferredSize(new Dimension(904, 708));
		this.setLayout(new BorderLayout(0, 0));

		JPanel panel = new JPanel();
		FlowLayout flowLayout = (FlowLayout) panel.getLayout();
		flowLayout.setAlignment(FlowLayout.LEFT);
		this.add(panel, BorderLayout.NORTH);

		JLabel lblComplaintId = new JLabel("Complaint ID:");
		lblComplaintId.setFont(new Font("Lucida Grande", Font.PLAIN, 18));
		panel.add(lblComplaintId);

		this.cbComplaintID = new JComboBox <>();
		this.cbComplaintID.setEnabled(false);
		this.cbComplaintID.setPreferredSize(new Dimension(75, 35));
		this.cbComplaintID.setFont(new Font("Lucida Grande", Font.PLAIN, 18));
		panel.add(this.cbComplaintID);

		JPanel panel_1 = new JPanel();
		this.add(panel_1, BorderLayout.CENTER);
		panel_1.setLayout(new BorderLayout(0, 0));

		JPanel panel_2 = new JPanel();
		panel_1.add(panel_2, BorderLayout.NORTH);

		JPanel panel_3 = new JPanel();
		panel_1.add(panel_3, BorderLayout.CENTER);
		panel_3.setLayout(new GridLayout(0, 2, 0, 0));

		JPanel panel_4 = new JPanel();
		panel_4.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
		panel_3.add(panel_4);
		panel_4.setLayout(new BorderLayout(0, 0));

		JPanel panel_17 = new JPanel();
		panel_4.add(panel_17, BorderLayout.WEST);
		panel_17.setLayout(new GridLayout(10, 0, 0, 0));

		JPanel panel_25 = new JPanel();
		FlowLayout flowLayout_9 = (FlowLayout) panel_25.getLayout();
		flowLayout_9.setVgap(10);
		flowLayout_9.setAlignment(FlowLayout.RIGHT);
		panel_17.add(panel_25);

		JLabel lblNewLabel_2 = new JLabel("Customer Name:");
		lblNewLabel_2.setFont(new Font("Lucida Grande", Font.PLAIN, 18));
		panel_25.add(lblNewLabel_2);

		JPanel panel_26 = new JPanel();
		FlowLayout flowLayout_14 = (FlowLayout) panel_26.getLayout();
		flowLayout_14.setVgap(10);
		panel_17.add(panel_26);

		JLabel lblNewLabel_3 = new JLabel("Customer SureName:");
		lblNewLabel_3.setFont(new Font("Lucida Grande", Font.PLAIN, 18));
		panel_26.add(lblNewLabel_3);

		JPanel panel_6 = new JPanel();
		panel_6.setBorder(new MatteBorder(0, 0, 1, 0, new Color(0, 0, 0)));
		FlowLayout flowLayout_10 = (FlowLayout) panel_6.getLayout();
		flowLayout_10.setVgap(10);
		flowLayout_10.setAlignment(FlowLayout.RIGHT);
		panel_17.add(panel_6);

		JLabel lblCustomerEmail = new JLabel("Customer eMail:");
		lblCustomerEmail.setFont(new Font("Lucida Grande", Font.PLAIN, 18));
		panel_6.add(lblCustomerEmail);

		JPanel panel_36 = new JPanel();
		FlowLayout flowLayout_15 = (FlowLayout) panel_36.getLayout();
		flowLayout_15.setVgap(10);
		flowLayout_15.setAlignment(FlowLayout.RIGHT);
		panel_17.add(panel_36);

		JLabel lblNewLabel_4 = new JLabel("Type:");
		lblNewLabel_4.setFont(new Font("Lucida Grande", Font.PLAIN, 18));
		panel_36.add(lblNewLabel_4);

		JPanel panel_38 = new JPanel();
		FlowLayout flowLayout_17 = (FlowLayout) panel_38.getLayout();
		flowLayout_17.setVgap(10);
		flowLayout_17.setAlignment(FlowLayout.RIGHT);
		panel_17.add(panel_38);

		JLabel lblNewLabel_5 = new JLabel("Open Date:");
		lblNewLabel_5.setFont(new Font("Lucida Grande", Font.PLAIN, 18));
		panel_38.add(lblNewLabel_5);

		JPanel panel_18 = new JPanel();
		FlowLayout flowLayout_3 = (FlowLayout) panel_18.getLayout();
		flowLayout_3.setVgap(10);
		flowLayout_3.setAlignment(FlowLayout.RIGHT);
		panel_17.add(panel_18);

		JLabel lblStatus = new JLabel("Status:");
		panel_18.add(lblStatus);
		lblStatus.setFont(new Font("Lucida Grande", Font.PLAIN, 18));

		JPanel panel_23 = new JPanel();
		FlowLayout flowLayout_4 = (FlowLayout) panel_23.getLayout();
		flowLayout_4.setVgap(10);
		flowLayout_4.setAlignment(FlowLayout.RIGHT);
		panel_17.add(panel_23);

		JLabel lblNewLabel = new JLabel("Resolve:");
		lblNewLabel.setFont(new Font("Lucida Grande", Font.PLAIN, 18));
		panel_23.add(lblNewLabel);

		JPanel panel_24 = new JPanel();
		FlowLayout flowLayout_5 = (FlowLayout) panel_24.getLayout();
		flowLayout_5.setVgap(10);
		flowLayout_5.setAlignment(FlowLayout.RIGHT);
		panel_17.add(panel_24);

		JLabel lblNewLabel_1 = new JLabel("Refund Amount:");
		lblNewLabel_1.setFont(new Font("Lucida Grande", Font.PLAIN, 18));
		panel_24.add(lblNewLabel_1);

		JPanel panel_19 = new JPanel();
		panel_4.add(panel_19, BorderLayout.CENTER);
		panel_19.setLayout(new GridLayout(10, 0, 0, 0));

		JPanel panel_29 = new JPanel();
		FlowLayout flowLayout_11 = (FlowLayout) panel_29.getLayout();
		flowLayout_11.setAlignment(FlowLayout.LEFT);
		panel_19.add(panel_29);

		this.tfCustomerName = new JTextField();
		this.tfCustomerName.setEditable(false);
		this.tfCustomerName.setFont(new Font("Lucida Grande", Font.PLAIN, 18));
		panel_29.add(this.tfCustomerName);
		this.tfCustomerName.setColumns(10);

		JPanel panel_30 = new JPanel();
		FlowLayout flowLayout_12 = (FlowLayout) panel_30.getLayout();
		flowLayout_12.setAlignment(FlowLayout.LEFT);
		panel_19.add(panel_30);

		this.tfCustomerSureName = new JTextField();
		this.tfCustomerSureName.setEditable(false);
		this.tfCustomerSureName.setFont(new Font("Lucida Grande", Font.PLAIN, 18));
		panel_30.add(this.tfCustomerSureName);
		this.tfCustomerSureName.setColumns(10);

		JPanel panel_28 = new JPanel();
		panel_28.setBorder(new MatteBorder(0, 0, 1, 0, new Color(0, 0, 0)));
		FlowLayout flowLayout_13 = (FlowLayout) panel_28.getLayout();
		flowLayout_13.setAlignment(FlowLayout.LEFT);
		panel_19.add(panel_28);

		this.tfCustomerEmail = new JTextField();
		this.tfCustomerEmail.setEditable(false);
		this.tfCustomerEmail.setFont(new Font("Lucida Grande", Font.PLAIN, 18));
		panel_28.add(this.tfCustomerEmail);
		this.tfCustomerEmail.setColumns(10);

		JPanel panel_37 = new JPanel();
		FlowLayout flowLayout_16 = (FlowLayout) panel_37.getLayout();
		flowLayout_16.setAlignment(FlowLayout.LEFT);
		panel_19.add(panel_37);

		this.tfComplaintType = new JTextField();
		this.tfComplaintType.setEnabled(false);
		this.tfComplaintType.setFont(new Font("Lucida Grande", Font.PLAIN, 18));
		panel_37.add(this.tfComplaintType);
		this.tfComplaintType.setColumns(10);

		JPanel panel_39 = new JPanel();
		FlowLayout flowLayout_18 = (FlowLayout) panel_39.getLayout();
		flowLayout_18.setAlignment(FlowLayout.LEFT);
		panel_19.add(panel_39);

		this.tfOpenDate = new JTextField();
		this.tfOpenDate.setEnabled(false);
		this.tfOpenDate.setFont(new Font("Lucida Grande", Font.PLAIN, 18));
		panel_39.add(this.tfOpenDate);
		this.tfOpenDate.setColumns(10);

		JPanel panel_21 = new JPanel();
		FlowLayout flowLayout_6 = (FlowLayout) panel_21.getLayout();
		flowLayout_6.setAlignment(FlowLayout.LEFT);
		panel_19.add(panel_21);

		this.cbComplaintStatus = new JComboBox <>();
		this.cbComplaintStatus.setEnabled(false);
		this.cbComplaintStatus.setModel(new DefaultComboBoxModel <>(ComplaintStatus.values()));
		this.cbComplaintStatus.setFocusable(false);
		this.cbComplaintStatus.setFont(new Font("Lucida Grande", Font.PLAIN, 18));
		panel_21.add(this.cbComplaintStatus);

		JPanel panel_20 = new JPanel();
		FlowLayout flowLayout_7 = (FlowLayout) panel_20.getLayout();
		flowLayout_7.setAlignment(FlowLayout.LEFT);
		panel_19.add(panel_20);

		this.cbComplaintResolve = new JComboBox <>();
		this.cbComplaintResolve.setEnabled(false);
		this.cbComplaintResolve.setModel(new DefaultComboBoxModel <>(ComplaintResolve.values()));
		this.cbComplaintResolve.setFont(new Font("Lucida Grande", Font.PLAIN, 18));
		this.cbComplaintResolve.setFocusable(false);
		panel_20.add(this.cbComplaintResolve);

		JPanel panel_22 = new JPanel();
		FlowLayout flowLayout_8 = (FlowLayout) panel_22.getLayout();
		flowLayout_8.setAlignment(FlowLayout.LEFT);
		panel_19.add(panel_22);

		this.ftfRefundAmount = new JFormattedTextField(NumberFormat.getIntegerInstance());
		this.ftfRefundAmount.setEnabled(false);
		this.ftfRefundAmount.setPreferredSize(new Dimension(100, 28));
		this.ftfRefundAmount.setFont(new Font("Lucida Grande", Font.PLAIN, 18));
		panel_22.add(this.ftfRefundAmount);

		JPanel panel_5 = new JPanel();
		panel_5.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
		panel_3.add(panel_5);
		panel_5.setLayout(new BorderLayout(0, 0));

		JPanel panel_7 = new JPanel();
		panel_5.add(panel_7, BorderLayout.SOUTH);

		JPanel panel_8 = new JPanel();
		panel_5.add(panel_8, BorderLayout.CENTER);
		panel_8.setLayout(new GridLayout(2, 0, 0, 0));

		JPanel panel_10 = new JPanel();
		panel_8.add(panel_10);
		panel_10.setLayout(new BorderLayout(0, 0));

		JPanel panel_11 = new JPanel();
		FlowLayout flowLayout_1 = (FlowLayout) panel_11.getLayout();
		flowLayout_1.setAlignment(FlowLayout.RIGHT);
		panel_11.setPreferredSize(new Dimension(180, 10));
		panel_10.add(panel_11, BorderLayout.WEST);

		JLabel lblComplaintText = new JLabel("Complaint Text:");
		lblComplaintText.setFont(new Font("Lucida Grande", Font.PLAIN, 18));
		panel_11.add(lblComplaintText);

		JPanel panel_12 = new JPanel();
		panel_10.add(panel_12, BorderLayout.EAST);

		JPanel panel_15 = new JPanel();
		panel_10.add(panel_15, BorderLayout.SOUTH);

		JScrollPane scrollPane = new JScrollPane();
		panel_10.add(scrollPane, BorderLayout.CENTER);

		this.taComplaintText = new JTextArea();
		this.taComplaintText.setEditable(false);
		this.taComplaintText.setFont(new Font("Lucida Grande", Font.PLAIN, 18));
		this.taComplaintText.setRows(10);
		this.taComplaintText.setFocusable(false);
		scrollPane.setViewportView(this.taComplaintText);

		JPanel panel_9 = new JPanel();
		panel_8.add(panel_9);
		panel_9.setLayout(new BorderLayout(0, 0));

		JPanel panel_13 = new JPanel();
		FlowLayout flowLayout_2 = (FlowLayout) panel_13.getLayout();
		flowLayout_2.setAlignment(FlowLayout.RIGHT);
		panel_13.setPreferredSize(new Dimension(180, 10));
		panel_9.add(panel_13, BorderLayout.WEST);

		JLabel lblComplaintResolve = new JLabel("Complaint Resolve:");
		lblComplaintResolve.setFont(new Font("Lucida Grande", Font.PLAIN, 18));
		panel_13.add(lblComplaintResolve);

		JPanel panel_14 = new JPanel();
		panel_9.add(panel_14, BorderLayout.EAST);

		JPanel panel_16 = new JPanel();
		panel_9.add(panel_16, BorderLayout.NORTH);

		JScrollPane scrollPane_1 = new JScrollPane();
		panel_9.add(scrollPane_1, BorderLayout.CENTER);

		this.taComplaintResolve = new JTextArea();
		this.taComplaintResolve.setEnabled(false);
		this.taComplaintResolve.setRows(10);
		this.taComplaintResolve.setFont(new Font("Lucida Grande", Font.PLAIN, 18));
		scrollPane_1.setViewportView(this.taComplaintResolve);

		JPanel panel_27 = new JPanel();
		panel_27.setPreferredSize(new Dimension(10, 60));
		panel_1.add(panel_27, BorderLayout.SOUTH);
		panel_27.setLayout(new GridLayout(0, 6, 0, 0));

		JPanel panel_31 = new JPanel();
		panel_27.add(panel_31);

		JPanel panel_32 = new JPanel();
		panel_27.add(panel_32);

		JPanel panel_33 = new JPanel();
		panel_27.add(panel_33);

		JPanel panel_34 = new JPanel();
		panel_27.add(panel_34);

		JPanel panel_35 = new JPanel();
		panel_27.add(panel_35);
		this.btnSubmit = new JButton(Common.BTN_SUBMIT);
		this.btnSubmit.setEnabled(false);
		panel_27.add(this.btnSubmit);
	}

	@Override
	protected void setupListeners ()
	{
		this.cbComplaintResolve.addItemListener(this);
		this.cbComplaintID.addItemListener(this);
		this.cbComplaintStatus.addItemListener(this);
		this.btnSubmit.addActionListener(this);

		this.taComplaintResolve.addKeyListener(this);
		this.ftfRefundAmount.addKeyListener(this);
	}

	@Override
	protected void setupButtonsIcons ()
	{
		int iconTextGap = 20;

		ImageIcon icon = UtilityHelper.getUtilityHelperInstance().loadScaledImage(Common.ICON_SUBMIT, 40, 40);
		if ( icon != null )
		{
			this.btnSubmit.setIcon(icon);
			this.btnSubmit.setIconTextGap(iconTextGap);
		}
	}

	/****************************************************************************************************************************
	 *** ActionListener methods ***
	 ****************************************************************************************************************************/
	@Override
	public void actionPerformed ( ActionEvent actionEvent )
	{
		if ( this.complaintUpdateListener != null )
		{
			boolean valid = true;

			ComplaintStatus status = (ComplaintStatus) this.cbComplaintStatus.getSelectedItem();
			ComplaintResolve resolve = null;
			String resolveText = this.taComplaintResolve.getText();
			Integer refundAmount = null;

			if ( this.cbComplaintResolve.isEnabled() )
			{
				resolve = (ComplaintResolve) this.cbComplaintResolve.getSelectedItem();
				if ( resolve == ComplaintResolve.REFUND )
				{
					refundAmount = Integer.parseInt(this.ftfRefundAmount.getText());
					valid = refundAmount > 0;
				}
			}

			if ( valid )
			{
				this.complaintUpdateListener.onComplaintUpdate(new ComplaintUpdateEvent(this, status, resolve, refundAmount, resolveText));
			}
			else
			{
				this.controllerDelegate.showPopUpMessage(UserNotification.COMPLAINT_REFUND_ISNT_VALID, PopUpMessageType.WARNING);
			}
		}
	}

	/****************************************************************************************************************************
	 *** ItemListener methods ***
	 ****************************************************************************************************************************/
	@Override
	public void itemStateChanged ( ItemEvent event )
	{
		if ( this.onScreen )
		{
			if ( event.getSource() == this.cbComplaintResolve )
			{
				if ( event.getStateChange() == ItemEvent.SELECTED
						|| event.getStateChange() == ItemEvent.DESELECTED )
				{
					this.setResolveEnabledAccordingStatus();
				}
			}
			else if ( event.getSource() == this.cbComplaintID )
			{
				if ( event.getStateChange() == ItemEvent.SELECTED )
				{
					if ( this.controllerDelegate != null )
					{
						Integer selectedComplaintID = (Integer) this.cbComplaintID.getSelectedItem();
						if ( selectedComplaintID != this.selectedComplaintID )
						{
							this.selectedComplaintID = selectedComplaintID;
							this.controllerDelegate.onButtonPress(selectedComplaintID);
						}
					}
				}
			}
			else if ( event.getSource() == this.cbComplaintStatus )
			{
				if ( event.getStateChange() == ItemEvent.SELECTED )
				{
					this.setResolveEnabledAccordingStatus();
				}
			}
		}
	}

	@Override
	public void keyTyped ( KeyEvent e )
	{
	}

	@Override
	public void keyPressed ( KeyEvent e )
	{
	}

	@Override
	public void keyReleased ( KeyEvent e )
	{
		if ( e.getSource() == this.taComplaintResolve )
		{
			String resovleText = this.taComplaintResolve.getText();
			boolean openSubmitBtn = ! UtilityHelper.getUtilityHelperInstance().isStringNullOrEmpty(resovleText);
			if ( openSubmitBtn )
			{
				if ( this.ftfRefundAmount.isEnabled() )
				{
					try
					{
						Integer refundCheck = Integer.parseInt(this.ftfRefundAmount.getText());
						openSubmitBtn = refundCheck > 0;
					}
					catch ( NumberFormatException nfe )
					{
						openSubmitBtn = ! openSubmitBtn;
					}
				}
			}
			this.btnSubmit.setEnabled(openSubmitBtn);
		}
		else if ( e.getSource() == this.ftfRefundAmount )
		{
			String refundAmount = this.ftfRefundAmount.getText();
			boolean openSubmitBtn = ! UtilityHelper.getUtilityHelperInstance().isStringNullOrEmpty(refundAmount);
			if ( openSubmitBtn )
			{
				try
				{
					Integer refundCheck = Integer.parseInt(this.ftfRefundAmount.getText());
					openSubmitBtn = refundCheck > 0;
					if ( openSubmitBtn )
					{
						String resovleText = this.taComplaintResolve.getText();
						openSubmitBtn = ! UtilityHelper.getUtilityHelperInstance().isStringNullOrEmpty(resovleText);
					}
				}
				catch ( NumberFormatException nfe )
				{
					openSubmitBtn = ! openSubmitBtn;
				}
			}
			this.btnSubmit.setEnabled(openSubmitBtn);
		}
	}
}
